package com.daotingli.backendprograms.Service.Admin.Authoer;

import com.daotingli.backendprograms.Repository.Admin.Authoer.AuthoerRepository;
import com.daotingli.backendprograms.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class AuthoerService {
    @Autowired
    private AuthoerRepository authoerRepository;
    public Result getAllAuthoers() {
        return Result.success(authoerRepository.getAllAuthoers());

    }

    public Result addAuthoer(String username, String password, String identity, String userphone, String userstate) {
        Map<String, Object> result = authoerRepository.addAuthoer(username, password, identity, userphone, userstate);
        if("success".equals(result.get("status"))){
            return Result.success();
        }else{
            return Result.error((String) result.get("message"));
        }
    }

    public Result deleteAuthoer(Integer id) {
        Map<String, Object> result = authoerRepository.deleteAuthoer(id);
        if("success".equals(result.get("status"))){
            return Result.success();
        }else{
            return Result.error((String) result.get("message"));
        }
    }

    public Result updateAuthoer(Integer id, String username, String password, String identity, String userphone, String userstate) {
        Map<String, Object> result = authoerRepository.updateAuthoer(id, username, password, identity, userphone, userstate);
        if("success".equals(result.get("status"))){
            return Result.success();
        }else{
            return Result.error((String) result.get("message"));
        }
    }
}
